<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title></title>
    <meta name="renderer" content="webkit"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="format-detection" content="telephone=no"/>
    <link rel="stylesheet" href="/resource/common/layui/css/layui.css" media="all"/>
    <link href="/resource/js/bstable/css/bootstrap.min.css" rel="stylesheet" type="text/css">
    <link href="/resource/css/table.css" rel="stylesheet" type="text/css">
</head>
<body style="background-color: #ecf0f5;font-family: 楷体;color: #475059;overflow: auto">
<div class="notice_main ">
    <div class="notice_check" style="padding: 16px 15px 8px 15px">
        <p>
            <label class="">留言用户：</label>
            <input type="text" id="userName" class="find_input">
            <label class="">留言时间：</label>
            <input type="text" class="find_input" id="timeJs">
            <button class="check_btn" id="search">查询</button>
        </p>
    </div>
    <table id="leaveWordTable" lay-filter="leaveWordTable"></table>
</div>
<script type="text/html" id="operate">
    <a class="toolbarMy" lay-event="del">删除</a>
    <a class="toolbarMy" lay-event="lookReply">查看回复</a>
    <a class="toolbarMy" lay-event="reply">回复</a>
</script>
<script type="text/javascript" src="/resource/common/layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['table', 'layer', 'laydate', 'form'], function () {
        var table = layui.table,
            $ = layui.$,
            layer = layui.layer,
            laydate = layui.laydate,
            form = layui.form;
        laydate.render({
            elem: '#timeJs'
            , type: 'datetime'//指定元素
            , range: '~' //或 range: '~' 来自定义分割字符
        });
        table.render({
            elem: '#leaveWordTable'
            , url: '/leaveWord/leaveWordTable.do' //数据接口
            , method: 'get'
            , page: true //开启分页
            , id: 'tableId'
            , limits: [10, 15, 30]
            , limit: 15
            , cols: [
                [ //表头
                    {field: 'userName', title: '留言用户', 'fixed': 'left'}
                    , {field: 'time', title: '留言时间'}
                    , {field: 'content', title: '留言内容'}
                    , {title: '操作', toolbar: '#operate', 'fixed': 'right'}
                ]
            ]
        });
        //监听工具条
        table.on('tool(leaveWordTable)', function (obj) {
            var data = obj.data;
            console.log(data);
            if (obj.event === 'del') {
                //删除
                delLeaveWord(data.id);
            } else if (obj.event === 'lookReply') {
                //查看回复
                layer.open({
                    type: 2,
                    title: "查看回复",
                    shadeClose: false, //点击遮罩关闭层
                    area: ['700px', '400px'],
                    content: "/leaveWord/lookReply.do?leaveId=" + data.id
                });
            } else if (obj.event === 'reply') {
                //查看回复
                layer.open({
                    type: 2,
                    title: "回复",
                    shadeClose: false, //点击遮罩关闭层
                    area: ['700px', '400px'],
                    content: "/leaveWord/reply.do?leaveId=" + data.id
                });
            }
        });
        //搜索
        $('#search').on('click', function () {
            active.reload();
        });

        //删除用户函数
        function delLeaveWord(id) {
            layer.confirm('是否删除?', function (index) {
                $.ajax({
                    url: "/leaveWord/leaveWord.do",
                    type: "post",
                    data: {_method: "DELETE", "id": id},
                    dataType: "json",
                    success: function (result) {
                        if (!result.status) {
                            layer.msg(result.msg, {time: 2000});
                            return false;
                        }
                        layer.msg("删除成功!", {time: 1000});
                        active.reload();
                    }
                });
                layer.close(index);
            });
        }

        //表格重载
        active = {
            reload: function () {
                var userName = $('#userName').val();
                var time = $('#timeJs').val();
                console.log(time)
                //执行重载
                table.reload('tableId', {
                    url: '/leaveWord/leaveWordTable.do'
                    , method: 'get'
                    , page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
                        "userName": userName,
                        "time": time
                    }
                });
            }
        }
    });
</script>

</body>
</html>